package com.youku.plugins.programListV4.view.items
{
   import flash.display.Sprite;
   import flash.display.DisplayObject;
   import flash.events.MouseEvent;
   import flash.geom.Rectangle;
   import com.youku.plugins.programListV4.view.event.ProgramListEvent;
   import com.youku.utils.AssetUtil;
   import com.youku.baseUI.BasePlayerButton;
   
   public class SliderBar extends Sprite
   {
      
      public function SliderBar() {
         super();
         this._value = 0;
         this._bg = AssetUtil.getAsset("Scrollbar_Bg");
         this.addChild(this._bg);
         var _loc1_:BasePlayerButton = AssetUtil.getStyleButton("Scrollbar");
         AssetUtil.restoreButtonSize(_loc1_);
         this._ball = new Sprite();
         this._ball.addChild(_loc1_);
         this.addChild(this._ball);
         this._ball.addEventListener(MouseEvent.MOUSE_DOWN,this.onBallMouseDown);
      }
      
      private var _bg:DisplayObject;
      
      private var _ball:Sprite;
      
      private var _value:Number;
      
      private function onBallMouseUp(param1:MouseEvent) : void {
         this._ball.stopDrag();
         stage.removeEventListener(MouseEvent.MOUSE_MOVE,this.onBallMove);
         stage.removeEventListener(MouseEvent.MOUSE_UP,this.onBallMouseUp);
      }
      
      private function onBallMouseDown(param1:MouseEvent) : void {
         this._ball.startDrag(false,new Rectangle(0,0,0,this._bg.height - this._ball.height));
         stage.addEventListener(MouseEvent.MOUSE_MOVE,this.onBallMove);
         stage.addEventListener(MouseEvent.MOUSE_UP,this.onBallMouseUp);
      }
      
      private function onBallMove(param1:MouseEvent) : void {
         this._value = this._ball.y / (this._bg.height - this._ball.height);
         this.dispatchEvent(new ProgramListEvent(ProgramListEvent.CHANGE));
      }
      
      public function get value() : Number {
         return this._value;
      }
      
      public function set value(param1:Number) : void {
         this._ball.y = (this._bg.height - this._ball.height) * param1;
         this._value = param1;
         this.dispatchEvent(new ProgramListEvent(ProgramListEvent.CHANGE));
      }
   }
}
